@extends('admin.layouts.app')
@section('css')
	<link href="{{asset('assets/plugins/select2/css/select2.min.css')}}" rel="stylesheet" type="text/css" />
 
@endsection
@section('content')


						 <div class="row">
                            <div class="col-sm-12">
                                <h4 class="page-title">平台管理</h4>
                                <ol class="breadcrumb">
                                    <li><a href="{{url('zadmin/')}}">系统</a></li>
                                    <li><a href="{{url('zadmin/product')}}">商品管理</a></li>
                                    <li class="active">添加商品</li>
                                </ol>
                            </div>
                        </div>
						

						
						<div class="row">
							<div class="col-sm-12">
								<div class="card-box">
                            				
        <form class="form-inline">
			<div class="form-group m-r-10">
			<label>商品名</label>
				<input type="text" class="form-control" name="name" placeholder="" value="{{array_get($where,'name')}}">
			</div>
			<div class="form-group m-r-10">
			<label for="exampleInputEmail2">类别</label>
			<select class="form-control" name="cate_id">
				<option value="">请选择品类</option>
				@foreach($cates as $cate)
				<option value="{{$cate->id}}" {{array_get($where,'cate_id')==$cate->id?'selected':''}}>{{$cate->name}}</option>
				@endforeach
				
			</select>
			</div>
			
												<button type="submit" class="btn btn-default waves-effect waves-light btn-md">
													搜索
												</button>
				<a href="{{url('zadmin/product/add')}}" class="btn btn-info waves-effect waves-light btn-md">
													添加
												</a>
											</form>
							</div>				
                         </div>

							<div class="col-sm-12">
								<div class="card-box">


									
		<div class="table-rep-plugin">
			<div class="table-responsive" >
				<table  class="table  table-striped">
					<thead>
						<tr>
							<th>ID</th>
							<th data-priority="1">品类</th>
							<th data-priority="1">商品名</th>
							<th data-priority="3">图片</th>
							<th data-priority="1">头车</th>
							<th data-priority="3">跟车</th>
							<th data-priority="3">价格</th>
							

							<th>市场价</th>
							
							
							<th>状态</th>							
							<th data-priority="6">操作</th>
						</tr>
					</thead>
					<tbody>
                        @foreach($list as $v)  
						<tr>
							<th>{{$v->id}}</th>
							<th>{{object_get($v,'cate.name')}}</th>
							<td>{{$v->name}}</td>
							<td><img src="{{$v->thumb}}" width="35" /></td>
							<td></td>

							<td></td>
							<td>{{$v->price}}</td>
														
							
														
							
							
							<td>{{$v->market_price}}</td>
							
							<td>{{$v->sale_txt}}</td>
							<td><a class="btn btn-white btn-sm" href="{{url('zadmin/product/edit')}}?product_id={{$v->id}}">修改</a>
							@if($v->on_sale)
							<button data-status=0 data-id="{{$v->id}}" class="btn btn-danger btn-sm saleStatus">下架</button>
							@else
							<button data-status=1 data-id="{{$v->id}}" class="btn btn-success btn-sm saleStatus">上架</button>
							@endif	
							</td>
						</tr>
                        @endforeach
													
												</tbody>
											</table>
										</div>
{{$list->appends($where)->links()}}
									</div>

								</div>
							</div>
						</div>



<div class="modal fade" id="statusModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
          &times;
        </button>
        <h4 class="modal-title" id="myModalLabel">
          操作
        </h4>
      </div>
       <form method="post" action="{{url('zadmin/product/sale-status')}}" >
      <div class="modal-body">
             
            <div class="form-group row">
                <label class="col-md-4 control-label">备注</label>
                <div class="col-md-8">
                  <textarea class="form-control" rows="5" name="remark" placeholder="备注"></textarea>
                </div>
            </div>
            <input type="hidden" name="id" id="product_id" value="" /> 
            <input type="hidden" name="status" id="status" value="">
       {{csrf_field()}}
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭
        </button>
        <button type="submit" class="btn btn-primary">
          确定
        </button>
      </div>
    </form>
    </div><!-- /.modal-content -->
  </div><!-- /.modal -->
</div>
 @endsection 
               
         

    @section('js')
        <script src="{{asset('assets/plugins/select2/js/select2.min.js')}}" type="text/javascript"></script>

      <script type="text/javascript">
      	var product_id = '';
      	var status = '';
      	$('.saleStatus').on('click',function(){
      		product_id = $(this).data('id');
      		status     = $(this).data('status');
      		$('#product_id').val(product_id);
      		$('#status').val(status);
      		$('#statusModal').modal('show');
      	});
      </script>
    @endsection    

